#ifndef _PARSER_H
#define _PARSER_H

#include <vector>
#include <string>
#include <iostream>
#include <fstream>
#include <cassert>

#include "classifier.h"
#include "sie.h"

using namespace std;

class parser {
   class inde {
      public:
      int nt,s,e,ind;
      inde(int pnt, int ps, int pe, int pind) {
	 nt = pnt;
	 s = ps;
	 e = pe;
	 ind = pind;
      }
   };
   class state {
      public:
      double prob;
      vector <int> iprod;
      vector <inde> c;

      state() {
	 prob=0;
      }

      bool operator == (const state &o) const {
	 return prob==o.prob && iprod==o.iprod;
      }
      bool operator != (const state &o) const {
	 return ! operator==(o);
      }
      bool operator < (const state &o) const {
	 return prob > o.prob;
      }
   };

   int getInd(pn &tsw, const vector <int> &si, const vector <int> &postagi, int i, int j, const vector <int> &ntw, const vector <int> &ntp, bool ef) const;
   bool firstAssign(vector <int> &start, vector <int> &end, int i, int j) const;
   bool nextAssign(vector <int> &start, vector <int> &end, int i, int j) const;   
   bool nextInd(vector <int> &v, const vector <int> &m) const;

   sie recover(const  vector <vector <vector <vector <state> > > > &p, const vector <leaf> &le, const vector <int> &intt, int n, int s, int e, int ind) const;

   public:

   void parse(const vector <leaf> &le, const vector <classifier> &cl, const vector <int> &words, const vector <int> &postags, const vector <cover> &co, const vector <int> &iterms, const vector <int> &inonterms, int istart, vector <sie> &r) const; 
};

#endif
